<template>
	<view>
	<free-nav-bar showback showright="true" title="发布朋友圈">
	
		<view slot="right" class="main-bg-color rounded mr-3 px-2 py-1" @click="saveback">
			<text class="font text-white">发布</text>
	
	
		</view>
	</free-nav-bar>
	<textarea placeholder="这一刻想法" v-model="content" class="p-3 font-md mb-3"></textarea>

	<free-upload-image v-if="type == 'image'"  @deleteee="shanchu":data="imageList" @upload="upload"></free-upload-image>
<view class="" v-if="type == 'video'">
	<view class="flex align-center justify-center bg-light"  v-if="!video" hover-class="bg-hover-light" @click="uploadvideo">
		<text class="text-muted" style="font-size: 100rpx;">+</text>
		
	</view>	
		<video :src="video" v-if="video" controls style="width: 100%;"></video>
		<view @click="uploadvideo" class="" v-if="video" class="my-3 flex justify-center align-center bg-light" hover-class="bg-hover-light" style="height: 100rpx;">
  <text class="font text-muted">点击切换视频</text> 			
		</view>
</view>


	<free-list-item title="所在位置"  showright isshowjt>
		<text class="iconfont font-lg py-2" slot="icon">&#xe647;</text>
		<view class="" slot="right">
			<text class="font-md" 
				>公开</text>
					
		</view>

	</free-list-item>
	<free-list-item title="提醒谁看"  showright isshowjt>
		<text class="iconfont font-lg py-2" slot="icon">&#xe611;</text>
		<view class="position-relative p-1" slot="right">

		</view>
	</free-list-item>
	<free-list-item title="谁可以看"  showright isshowjt>
		<text class="iconfont font-lg py-2" slot="icon">&#xe611;</text>
		<view class="position-relative p-1" slot="right">

		</view>
	</free-list-item>
	</view>
</template>

<script>
	import freeNavBar from "@/components/free-ui/free-nav-bar.vue"
		import freeUploadImage from "@/components/free-ui/free-upload-image.vue"
	import freeListItem from "@/components/free-ui/free-list-item.vue"
		import $H from '../../../../utils/request.js';
	export default {
		components:{
			freeNavBar,
			freeUploadImage,
			freeListItem
		},
		data() {
			return {
			imageList:[],	
			video:"",
			type:"",
			
			content:""
			}
		},
		
		onLoad(e) {
			console.log(e,"e");
	this.type=e.type
	
		},
		methods: {
			saveback(){
				$H.post("moment/create",{
					content:this.content,
					type:this.type,
					see:"all",
			image:this.imageList.length == 0? '':this.imageList.join(","),
			video:this.video,
			location:""
				}).then(res=>{
					if(res){
						uni.showToast({
							title:"发布成功",
							icon:"none"
						});
						uni.navigateBack({
							delta:1
						})
						
					}
				})
			},
			uploadvideo(){
				uni.chooseVideo({
					// maxDuration:10,
					success: (res) => {
						uni.uploadFile({
							url: 'http://127.0.0.1:7001/upload',
							header: {
								token: uni.getStorageSync("token")
							}, //仅为示例，非真实的接口地址
							filePath: res.tempFilePath,
							name: 'file',
							success: (uploadFileRes) => {
								console.log(uploadFileRes.data,
									"uploadFileResdata");
								let data = JSON.parse(uploadFileRes.data)
								console.log(data, "uploadFileResdata1");
						 this.video=data.data	
								
							}
						})
					// this.video=res.tempFilePath	
					}
				})
			},
			shanchu(e){
				this.imageList=e
				
			},
			upload(e){
				console.log(e,"eeeee")
				this.imageList=e
			},
			chooseimage(){
				uni.chooseImage({
					count:9-this.imageList.length,
					sizeType:['compressed'],
					success: (res) => {
	this.imageList=[...this.imageList, ...res.tempFilePaths]
	console.log(this.imageList,"this.imageList")
					}
				})
			}
		}
	}
</script>

<style>

</style>
